package huawei;

import java.util.LinkedList;

/**
 * @author Wenhao Tong
 * @create 2021-07-31 11:06
 */
public class MinStack {

    private LinkedList<Integer> stack;
    private LinkedList<Integer> min;

    public MinStack () {
        stack = new LinkedList<>();
        min = new LinkedList<>();
    }

    public void push(Integer i) {
        stack.push(i);
        if (min.size() == 0) {
            min.push(i);
        }
        if (min.peek() > i) {
            min.push(i);
        }
    }

    public void pop() {
        if (stack.size() == 0) {
            return;
        }
        stack.pop();
    }

    public Integer top() {
        if (stack.size() == 0) {
            return null;
        }
        return stack.peek();
    }

    public Integer getMin() {
        if (stack.size() == 0) {
            return null;
        }
        return min.peek();
    }
}
